package $15_object;

//java.util.Objects这个类是1.7引入的，重写那几个常用方法就会出现下面这行
import java.util.Objects;

public class Student 
{
	private String name;
	private int age;
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public int getAge()
	{
		return age;
	}
	public void setAge(int age)
	{
		this.age = age;
	}
	public Student()
	{
		
	}
	public Student(String name, int age)
	{
		this.name = name;
		this.age = age;
	}
	//重写toString方法（eclipse右键空白处[source]-->[generate to String()]）
	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}
	//重写hashCode
	@Override
	public int hashCode() {
		return Objects.hash(age, name);
	}
	//重写equals
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		return age == other.age && Objects.equals(name, other.name);
	}
	

}
